
public class Vector {

	double[] rep;
	int size;
	public Vector(int size){
		rep = new double[size];
	}
	
	public Vector projectionOnto(Vector v){
		return v.multiply(this.dot(v)/v.dot(v));
	}
	
	public boolean isOrthogonal(Vector v){
		return this.dot(v)<.0000001;
	}
	
	public double angleBetweenRadians(Vector v){
		return Math.acos((this.dot(v)/(this.length()*v.length())));
	}
	
	
	public double distance(Vector v){
		return this.subtract(v).length();
	}
	
	public Vector(double[] in){
		size=in.length;
		rep = in;
	}
	
	public Vector normalize(){
		return this.divide(this.length());
	}
	
	public Vector add(Vector v){
		double[] result = new double[size];
		for(int i=0;i<size;i++){
			result[i]=rep[i]+v.rep[i];
		}
		return new Vector(result);
	}
	
	public Vector multiply (double scalar){
		double[]result = new double[size];
		for(int i=0;i<size;i++){
			result[i]=rep[i]*scalar;
		}
		return new Vector(result);
	}
	
	public Vector divide(double scalar){
		return this.multiply(1/scalar);
	}
	
	public Vector subtract(Vector v){
		return this.add(v.multiply(-1));
	}
	
	public double dot(Vector v){
		double result = 0;
		for(int i=0;i<size;i++){
			result +=(rep[i]*v.rep[i]);
		}
		return result;
	}
	
	public double length(){
		return  Math.sqrt(this.dot(this));
	}
	
	public String toString(){
		StringBuilder result = new StringBuilder("["+rep[0]);
		for(int i=1;i<size;i++){
			result.append(","+rep[i]);
		}
		result.append("]");
		return result.toString();
	}
}
